const { Article} = require('../../model/article')

module.exports = async (req,res) => {
    req.app.locals.currentLink = 'article'

    // 页码
    let page = req.query.page || 1;
    // 每页条数
    let pageSize = 3
    // 数据总数
    let totle = await Article.countDocuments({})
    // 总页数
    let pageNum = Math.ceil(totle / pageSize) 

    let articles = await Article.find({}).populate('author').skip((page - 1) * pageSize).limit(pageSize)
    // console.log(articles);
    res.render('../views/admin/article',{
        username:req.session.username,
        articles,
        totle,
        pageNum,
        page,
    })
}